package cn.yangliu.init;

import com.alibaba.excel.event.AnalysisEventListener;
import lombok.SneakyThrows;

/**
 * The type of package-scan.
 *
 * <p>
 * .
 *
 * @param <T> the type parameter
 * @author 问道于盲
 * @date 2020 -04-16
 */
public class InitAction<T> {

    /**
     * 要读取的sheet名称
     */
    private final String sheet;

    /**
     * 排序号
     */
    private final int order;

    /**
     * 数据模型类
     */
    private final Class<T> modelClass;

    /**
     * 数据处理监听器
     */
    private final Class<? extends AnalysisEventListener<T>> listener;

    /**
     * Instantiates a new Init action.
     * allow any class to create a new instance.
     *
     * @param sheet      the sheet
     * @param order      the order
     * @param modelClass the model class
     * @param listener   the listener
     */
    public InitAction(String sheet, int order,
                      Class<T> modelClass,
                      Class<? extends AnalysisEventListener<T>> listener) {
        this.sheet = sheet;
        this.order = order;
        this.modelClass = modelClass;
        this.listener = listener;
    }

    /**
     * Sheet string.
     *
     * @return the string
     */
    public String sheet() {
        return sheet;
    }

    /**
     * Order int.
     *
     * @return the int
     */
    public int order() {
        return order;
    }

    /**
     * Model class class.
     *
     * @return the class
     */
    public Class<T> modelClass() {
        return modelClass;
    }

    /**
     * Listener analysis event listener.
     *
     * @return the analysis event listener
     */
    @SneakyThrows
    public AnalysisEventListener<T> listener() {
        return listener.newInstance();
    }

}
